const express = require('express');
const router = express.Router();
const mysql=require('mysql');

let connection=mysql.createPool({
  host     : 'rm-uf6hsi42u17lj6t8hmo.mysql.rds.aliyuncs.com',
  user     : 'root',
  password : 'Cjy199387',
  port: '3306',
  database:'userinfo'
});

function query(sql,callback){
  connection.getConnection(function(err,connection){
    connection.query(sql, function (err,rows) {
      callback(err,rows);
      connection.release();
    });
  });
}
/* GET home page. */
let sql='';
router.get('/', function(req, res, next) {
  console.log(req.session);
  if(req.session.user){
    let user=req.session.user;
    res.send('你好'+user.name+'，欢迎来到我的家园。');
  }else{
    res.send('你还没有登录，先登录下再试试！');
  }
});
router.post('/inf/source/getCompanyAndProductBySource', function(req, res, next) {
  if(req.sourceCode){
    res.send({
      code:200,
      data:{
        productData:{
          productName:'育苗'
        },
        companyData:{}
      }
    });
  }else{
    res.send({
      code:400,
    });
  }
  
});

module.exports = router;
